home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectSound / EnumDevice / frmEnum.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-10-08  |  5.0 KB  |  151 lines

  1. VERSION 5.00
  2. Begin VB.Form frmEnum 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "EnumDevices"
  5.    ClientHeight    =   1740
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   3960
  9.    Icon            =   "frmEnum.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   1740
  14.    ScaleWidth      =   3960
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.ComboBox cboCapture 
  17.       Height          =   315
  18.       Left            =   1320
  19.       Style           =   2  'Dropdown List
  20.       TabIndex        =   6
  21.       Top             =   840
  22.       Width           =   2535
  23.    End
  24.    Begin VB.ComboBox cboSound 
  25.       Height          =   315
  26.       Left            =   1320
  27.       Style           =   2  'Dropdown List
  28.       TabIndex        =   5
  29.       Top             =   420
  30.       Width           =   2535
  31.    End
  32.    Begin VB.CommandButton cmdExit 
  33.       Cancel          =   -1  'True
  34.       Caption         =   "E&xit"
  35.       Height          =   315
  36.       Left            =   2880
  37.       TabIndex        =   4
  38.       Top             =   1260
  39.       Width           =   975
  40.    End
  41.    Begin VB.CommandButton cmdCreate 
  42.       Caption         =   "&Create"
  43.       Default         =   -1  'True
  44.       Height          =   315
  45.       Left            =   120
  46.       TabIndex        =   3
  47.       Top             =   1260
  48.       Width           =   975
  49.    End
  50.    Begin VB.Label Label1 
  51.       BackStyle       =   0  'Transparent
  52.       Caption         =   "Capture Device:"
  53.       Height          =   255
  54.       Index           =   2
  55.       Left            =   120
  56.       TabIndex        =   2
  57.       Top             =   900
  58.       Width           =   1215
  59.    End
  60.    Begin VB.Label Label1 
  61.       BackStyle       =   0  'Transparent
  62.       Caption         =   "Sound Device:"
  63.       Height          =   255
  64.       Index           =   1
  65.       Left            =   120
  66.       TabIndex        =   1
  67.       Top             =   480
  68.       Width           =   1215
  69.    End
  70.    Begin VB.Label Label1 
  71.       BackStyle       =   0  'Transparent
  72.       Caption         =   "This sample shows how to enumerate devices."
  73.       Height          =   255
  74.       Index           =   0
  75.       Left            =   120
  76.       TabIndex        =   0
  77.       Top             =   60
  78.       Width           =   4455
  79.    End
  80. Attribute VB_Name = "frmEnum"
  81. Attribute VB_GlobalNameSpace = False
  82. Attribute VB_Creatable = False
  83. Attribute VB_PredeclaredId = True
  84. Attribute VB_Exposed = False
  85. Option Explicit
  86. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  87. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  88. '  File:       frmEnum.frm
  89. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  90. Private dx As New DirectX8
  91. Private dsEnum As DirectSoundEnum8
  92. Private dscEnum As DirectSoundEnum8
  93. Private ds As DirectSound8
  94. Private dsc As DirectSoundCapture8
  95. Private Sub cmdCreate_Click()
  96.     On Error GoTo FailedCreate
  97.         
  98.     'Create a DirectSound object
  99.     Set ds = dx.DirectSoundCreate(dsEnum.GetGuid(cboSound.ListIndex + 1))
  100.     Set ds = Nothing 'We should get rid of it now, since we don't want to fail
  101.                      'If the machine doesn't support full duplex
  102.                      
  103.     'Create a Capture Buffer
  104.     Set dsc = dx.DirectSoundCaptureCreate(dscEnum.GetGuid(cboCapture.ListIndex + 1))
  105.     Set dsc = Nothing 'Release it
  106.     'Notify the user we succeeded
  107.     MsgBox "DirectSound8 and DirectSoundCapture8 object creation succeeded.", vbOKOnly Or vbInformation, "Success"
  108.     Exit Sub
  109. FailedCreate:
  110.     'Notify the user we failed
  111.     MsgBox "DirectSound8 and DirectSoundCapture8 object creation failed.", vbOKOnly Or vbInformation, "Failure"
  112. End Sub
  113. Private Sub cmdExit_Click()
  114.     'We're done exit
  115.     Unload Me
  116. End Sub
  117. Private Sub CleanUp()
  118.     Set dscEnum = Nothing
  119.     Set dsEnum = Nothing
  120.     Set dx = Nothing
  121. End Sub
  122. Private Sub Form_Load()
  123.     'Enum the devices and load them into the box
  124.     LoadEnum
  125. End Sub
  126. Private Sub LoadEnum()
  127.     Dim lCount As Long
  128.     On Error GoTo FailedEnum
  129.     Set dsEnum = dx.GetDSEnum
  130.     Set dscEnum = dx.GetDSCaptureEnum
  131.     'Add each description to the combo box
  132.     For lCount = 1 To dsEnum.GetCount
  133.         cboSound.AddItem dsEnum.GetDescription(lCount)
  134.     Next
  135.     'Add each description to the combo box
  136.     For lCount = 1 To dscEnum.GetCount
  137.         cboCapture.AddItem dscEnum.GetDescription(lCount)
  138.     Next
  139.     On Error Resume Next
  140.     'Select the first item in each combo box
  141.     cboCapture.ListIndex = 0
  142.     cboSound.ListIndex = 0
  143.     Exit Sub
  144. FailedEnum:
  145.     MsgBox "Error enumerating DirectSound devices. " & vbCrLf & "Sample will now exit.", vbOKOnly Or vbInformation, "DirectSound Sample"
  146.     Unload Me
  147. End Sub
  148. Private Sub Form_Unload(Cancel As Integer)
  149.     CleanUp
  150. End Sub
  151.